package cn.com.zhuxulin.android.demos.activities;

import cn.com.zhuxulin.android.demos.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class AlertDialogDemos extends Activity {
	private Button general = null;
	private Button singleChoice = null;
	private Button multiChoice = null;
	private Button viewInput = null;
	private Button items = null;
	private Builder dialog = null;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.alert_dialog);
		general = (Button) findViewById(R.id.general);
		singleChoice = (Button) findViewById(R.id.single);
		multiChoice = (Button) findViewById(R.id.multi);
		viewInput = (Button) findViewById(R.id.view);
		items = (Button) findViewById(R.id.items);
	}

	@Override
	public void onStart() {
		super.onStart();
		general.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				// TODO Show General AlertDialog
				dialog = new AlertDialog.Builder(AlertDialogDemos.this);
				dialog.setTitle("General");
				dialog.setMessage("Show a general alertdialog");
				dialog.setPositiveButton(R.string.PositiveButton, null);
				dialog.setNegativeButton(R.string.NegativeButton, null);
				dialog.setNeutralButton(R.string.NeutralButton, null);
				dialog.show();
			}
		});

		singleChoice.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				// TODO Show Single Choice AlertDialog
				dialog = new AlertDialog.Builder(AlertDialogDemos.this);
				dialog.setTitle("SingleChoice");
				dialog.setSingleChoiceItems(
						new String[] { "111", "222", "333" }, 0, null);
				dialog.setPositiveButton(R.string.PositiveButton, null);
				dialog.setNegativeButton(R.string.NegativeButton, null);
				dialog.setNeutralButton(R.string.NeutralButton, null);
				dialog.show();
			}
		});

		multiChoice.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				// TODO Show Multiple Choice AlertDialog
				dialog = new AlertDialog.Builder(AlertDialogDemos.this);
				dialog.setTitle("MultiChoice");
				dialog.setMultiChoiceItems(
						new String[] { "111", "222", "333" }, new boolean[] {
								false, false, false }, null);
				dialog.setPositiveButton(R.string.PositiveButton, null);
				dialog.setNegativeButton(R.string.NegativeButton, null);
				dialog.setNeutralButton(R.string.NeutralButton, null);
				dialog.show();
			}
		});

		viewInput.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				// TODO Show View AlertDialog
				dialog = new AlertDialog.Builder(AlertDialogDemos.this);
				dialog.setTitle("ViewAlertDialog");
				dialog.setView(new EditText(AlertDialogDemos.this));
				dialog.setPositiveButton(R.string.PositiveButton, null);
				dialog.setNegativeButton(R.string.NegativeButton, null);
				dialog.setNeutralButton(R.string.NeutralButton, null);
				dialog.show();
			}
		});

		items.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				// TODO Show Items AlertDialog
				dialog = new AlertDialog.Builder(AlertDialogDemos.this);
				dialog.setTitle("Items");
				dialog.setItems(new String[] { "111", "222", "333" }, null);
				dialog.setPositiveButton(R.string.PositiveButton, null);
				dialog.setNegativeButton(R.string.NegativeButton, null);
				dialog.setNeutralButton(R.string.NeutralButton, null);
				dialog.show();
			}
		});
	}
}